//
//  PreferredCollectionViewCell.m
//  MobileShoppingMall
//
//  Created by 冯传昌 on 2021/4/16.
//  Copyright © 2021 冯传昌. All rights reserved.
//

#import "PreferredCollectionViewCell.h"

#define cellWidth ((ScreenWidth-12)/2-10)

#define cellHeight ((ScreenWidth-12)/2-10)*1.7

@interface PreferredCollectionViewCell()

@property (nonatomic,strong) UIView *bgView;

@property (nonatomic,strong) UIImageView *goodsImgV;//商品图片
@property (nonatomic,strong) UILabel *goodsInfoLB;//商品介绍lb
@property (nonatomic,strong) UILabel *goodsPriceLB;//商品价格lb

@property (nonatomic,strong) UIView *lineV;//分隔线

@property (nonatomic,strong) UIImageView *storeLogoImgV;//商店logo
@property (nonatomic,strong) UILabel *storeNameLB;//商店名lb

@end

@implementation PreferredCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame{
    if (self == [super initWithFrame:frame]) {
        [self initUI];
    }
    return self;
}

#pragma mark - setter
- (void)setModel:(MainPageGoodsModel *)model{
    _model = model;
    
    self.storeNameLB.text = _model.company;
    self.goodsInfoLB.text = _model.name;
    self.goodsPriceLB.text = [Configuration getTotalPriceWithPrice:_model.minprice withTbPrice:_model.mintbprice];
        
    dispatch_async(dispatch_get_main_queue(), ^{
        [self.goodsImgV sd_setImageWithURL:[NSURL URLWithString:model.listpic] placeholderImage:LoadImage(@"")];
        [self.storeLogoImgV sd_setImageWithURL:[NSURL URLWithString:model.logo] placeholderImage:LoadImage(@"首页_商店图标1")];
    });
}

#pragma mark - UI
-(void)initUI{
    [self addSubview:self.bgView];
    [self.bgView addSubview:self.goodsImgV];
    [self.bgView addSubview:self.goodsInfoLB];
    [self.bgView addSubview:self.goodsPriceLB];
    [self.bgView addSubview:self.lineV];
    [self.bgView addSubview:self.storeLogoImgV];
    [self.bgView addSubview:self.storeNameLB];
}

#pragma mark - lazy
- (UIView *)bgView{
    if (!_bgView) {
        _bgView = [[UIView alloc] initWithFrame:self.bounds];
        _bgView.backgroundColor = UIColor.whiteColor;
        _bgView.clipsToBounds = YES;
        _bgView.layer.cornerRadius = 4;
    }
    return _bgView;
}

- (UIImageView *)goodsImgV{
    if (!_goodsImgV) {
        _goodsImgV = [[UIImageView alloc] initWithFrame:CGRectMake(28*Width_Scale, 20*Width_Scale, cellWidth-56*Width_Scale, cellWidth-56*Width_Scale)];
        _goodsImgV.image = LoadImage(@"首页_商品占位图4");
    }
    return _goodsImgV;
}
- (UILabel *)goodsInfoLB{
    if (!_goodsInfoLB) {
        _goodsInfoLB = [[UILabel alloc] initWithFrame:CGRectMake(16, self.goodsImgV.bottom+20, cellWidth-32, 38)];
        _goodsInfoLB.numberOfLines = 0;
        _goodsInfoLB.font = FontSet(14);
        _goodsInfoLB.textAlignment = NSTextAlignmentCenter;
        _goodsInfoLB.textColor = MainBlackTextColor;
        _goodsInfoLB.text = @"Apple Watch Series 3 银色铝金属表壳…";
    }
    return _goodsInfoLB;
}
- (UILabel *)goodsPriceLB{
    if (!_goodsPriceLB) {
        _goodsPriceLB = [[UILabel alloc] initWithFrame:CGRectMake(16, self.goodsInfoLB.bottom+10, cellWidth-32, 22)];
        _goodsPriceLB.font = FontSetWithWeight(16, 0.3f);
        _goodsPriceLB.textAlignment = NSTextAlignmentLeft;
        _goodsPriceLB.textColor = RGB(255, 34, 21);
        _goodsPriceLB.text = @"¥1999+100TB";
    }
    return _goodsPriceLB;
}

- (UIView *)lineV{
    if (!_lineV) {
        _lineV = [[UIView alloc] initWithFrame:CGRectMake(15, cellHeight-44, cellWidth-30, 1)];
        _lineV.backgroundColor = RGBA(0, 0, 0, 0.03f);
    }
    return _lineV;
}

- (UIImageView *)storeLogoImgV{
    if (!_storeLogoImgV) {
        _storeLogoImgV = [[UIImageView alloc] initWithFrame:CGRectMake(16, cellHeight - 32, 18, 18)];
        _storeLogoImgV.image = LoadImage(@"首页_商店图标1");
    }
    return _storeLogoImgV;
}

- (UILabel *)storeNameLB{
    if (!_storeNameLB) {
        _storeNameLB = [[UILabel alloc] initWithFrame:CGRectMake(self.storeLogoImgV.right+6, self.storeLogoImgV.top+1, cellWidth - 44, 16)];
        _storeNameLB.font = FontSet(11);
        _storeNameLB.textAlignment = NSTextAlignmentLeft;
        _storeNameLB.textColor = MainGrayTextColor;
        _storeNameLB.text = @"Apple官方自营旗舰店";
    }
    return _storeNameLB;
}


@end
